//
//  MMGNavigationController.swift
//  MyMicroblog
//
//  Created by Mac on 17/1/4.
//  Copyright © 2017年 itcast. All rights reserved.
//

import UIKit

class MMGNavigationController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = UIColor.white
    }

    // 重写 push 跳转方法,设置 bottomBar
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        // 判断是否为压栈状态
        if viewControllers.count > 0 {
        
            // 设置左导航按钮
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(imageName: "navigationbar_back_withtext", imageNameSel: "navigationbar_back_withtext_highlighted", title: "返回", target: self, action: #selector(popSelf))
            
            viewController.hidesBottomBarWhenPushed = true
        }
        
        
        super.pushViewController(viewController, animated: true)
    }
    
    // 为左侧 barButtonItem 提供返回方法
    @objc private func popSelf() {
    
        self.popViewController(animated: true)
    }

}
